﻿using System;
using System.Collections.Generic;
using System.Windows;
using Brjnk.Common;

namespace Brjnk.GpxExplorer.UI
{
    /// <summary>
    /// Interaction logic for CoordinatesToClipboardWindow.xaml
    /// </summary>
    public partial class CoordinatesToClipboardWindow : Window
    {
        private GpsCoordinates coordinates;

        private string[] items;

        public CoordinatesToClipboardWindow(GpsCoordinates coordinates)
        {
            this.coordinates = coordinates;
            GenerateItems();
            this.Closing += new System.ComponentModel.CancelEventHandler(CoordinatesToClipboardWindow_Closing);
            InitializeComponent();
        }

        private void CoordinatesToClipboardWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            closing = true;
        }

        private bool closing = false;

        private new void Close()
        {
            if (!closing)
            {
                closing = true;
                base.Close();
            }
        }

        private void ButtonClicked(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void GenerateItems()
        {
            items = new string[] {coordinates.ToString(Common.CoordinationFormat.Degrees),
                coordinates.ToString(Common.CoordinationFormat.Minutes),
                coordinates.ToString(Common.CoordinationFormat.Seconds),
                coordinates.ToString("d5s",System.Globalization.CultureInfo.CurrentCulture),
                coordinates.ToString("m4s",System.Globalization.CultureInfo.CurrentCulture),
                coordinates.ToString("s2s",System.Globalization.CultureInfo.CurrentCulture),
            };
        }

        public IEnumerable<string> Items
        {
            get { return items; }
        }

        private void Window_Deactivated(object sender, EventArgs e)
        {
            Close();
        }
    }
}